package Hander;

import View.EnrollView;
import entity.AdminDo;
import service.AdminService;
import service.AdminServiceImpl;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EnrollViewHander implements ActionListener {
    private EnrollView enrollView;
    public EnrollViewHander(EnrollView enrollView) {
        this.enrollView = enrollView;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text=jButton.getText();
        if("注册".equals(text)){
            AdminService adminService=new AdminServiceImpl();

            AdminDo adminDo=enrollView.buildmanger();

            boolean result= adminService.enroll(adminDo);
            if(result){
                JOptionPane.showMessageDialog(enrollView,"注册成功");
                enrollView.dispose();
            }else{
                System.out.println("添加错误！");
                JOptionPane.showMessageDialog(enrollView,"添加失败");
            }
        }
    }
}
